package com.fenqing.leetcode.code.t1600_1700;

import com.fenqing.annotations.DesignClass;
import com.fenqing.core.design.DesignTopic;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fenqing
 */
public class Topic1656 extends DesignTopic {
    public Topic1656(String methods, String params) {
        super(methods, params);
    }

    @DesignClass
    public static class OrderedStream {

        private String[] values;

        private int ptr;

        public OrderedStream(int n) {
            this.ptr = 1;
            this.values = new String[n];
        }

        public List<String> insert(int idKey, String value) {
            this.values[idKey - 1] = value;
            List<String> result = new ArrayList<>();
            while (this.ptr <= this.values.length && this.values[this.ptr - 1] != null){
                result.add(this.values[this.ptr++ - 1]);
            }
            return result;
        }
    }

    public static void main(String[] args) {
        System.out.println(new Topic1656(
                "[\"OrderedStream\",\"insert\",\"insert\",\"insert\",\"insert\",\"insert\"]",
                "[[5],[3,\"ccccc\"],[1,\"aaaaa\"],[2,\"bbbbb\"],[5,\"eeeee\"],[4,\"ddddd\"]]"
        ).run());
    }

}
